import { createRouter, createWebHashHistory } from 'vue-router'
import {mainStore} from "../../store";
import {verify} from "../api/login";

const routes = [
    {
        path: '/',
        name: 'index',
        component: () => import('../components/index/index.vue')
    },
    {
        path: '/login',
        name: '',
        component: () => import('../components/login/index.vue')
    },
    {
        path: '/text',
        name: '',
        component: () => import('../components/text.vue')
    },
    {
        path: '/search',
        name: 'search',
        component: () => import('../components/searchgame/index.vue')
    },
    {
        path: '/play',
        name: 'play',
        component: () => import('../components/playgame/index.vue')
    },
    {
        path: '/exegame',
        name: 'exegame',
        component: () => import('../components/showgameforexe/index.vue')
    },
    {
        path: '/user',
        name: 'user',
        component: () => import('../components/user/index.vue'),
        children:[
            {
                path: 'mygame',
                component: () => import('../components/user/mygame/index.vue'),
            },
            {
                path: 'historycomments',
                component: () => import('../components/user/historycomments/index.vue'),
            },
            {
                path: 'personalinfo',
                component: () => import('../components/user/personalinfo/index.vue'),
            },
            {
                path: '',
                component: () => import('../components/user/mygame/index.vue'),
            }
        ]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})


// router.beforeEach((to, from, next) => {
//     if (localStorage.getItem('token')){
//         let token = localStorage.getItem('token');
//         if (token === null || token === '') {
//             const { loginout } = mainStore()
//             loginout()
//         } else {
//             next();
//         }
//     }
// })


export default router
